<template>
    <div v-if="visible" class="loading-overlay">
        <div class="loading-content">
            <div class="spinner"></div>
            <p class="loading-text">{{ text }}</p>
        </div>
    </div>
</template>

<script setup>
import { defineProps } from 'vue';

// 接收外部传入的属性
defineProps({
    visible: {
        type: Boolean,
        default: false, // 控制蒙版是否显示
    },
    text: {
        type: String,
        default: '加载中...', // 加载提示文字
    },
});
</script>

<style scoped lang="less">
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    /* 半透明背景 */
    backdrop-filter: blur(30px);
    /* 毛玻璃效果 */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    white-space: pre-wrap
    /* 确保在最上层 */
}

.loading-content {
    display: flex;
    flex-direction: column; /* 垂直排列 */
    align-items: center;    /* 水平居中 */
    justify-content: center; /* 垂直居中 */
    text-align: center;    
    color: #fff;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px auto;
}

.loading-text {
    font-size: 16px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
</style>